package com.commont;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.Reader;
import java.net.URL;
import java.nio.charset.Charset;
import java.util.concurrent.CyclicBarrier;

import com.google.gson.JsonObject;
import com.google.gson.JsonParser;
import lombok.extern.slf4j.Slf4j;


/**
 * 测试专用
 */
@Slf4j
public class MainTest {
    //学生总数
    private static final Integer STUDENT_COUNT=12;
    /**
     * 人数到齐开门回家
     */
    static final CyclicBarrier barrier=new CyclicBarrier ( 3, new Runnable () {
        @Override
        public void run() {
            log.info ( "3个人数到齐，开门" );
        }
    } );

    public static void goHome()throws Exception{
        log.info ( Thread.currentThread ().getName ()+"已刷卡等待回家" );
        barrier.await ();
       // log.info ( Thread.currentThread ().getName ()+"已经出校门!回家了" );
    }


    public static void main(String[] args) {
        for (Integer i = 0; i < STUDENT_COUNT; i++) {
            new Thread ( "学生"+i+"" ){
                public void run(){
                    try {
                        goHome ();
                    } catch (Exception e) {
                        e.printStackTrace ();
                    }
                }
            }.start ();
        }

    }


}
